package com.hmsproject.db.inmemorydb;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hmsproject.datastructures.deal.Deal;

public class WatchListMap {
	
	private static WatchListMap  INSTANCE = new WatchListMap();
	
	private WatchListMap(){
		
	}
	
	private Map<String, List<String>> watchListMap = new HashMap<>();
	
	
	public static boolean addToWatchList(String emailId,String dealId){
		List<String> dealList = INSTANCE.watchListMap.get(emailId);
		if(dealList == null){
			dealList = new ArrayList<String>();
			INSTANCE.watchListMap.put(emailId, dealList);
		}
		dealList.add(emailId);
		return true;
	}
	
	
	public static boolean removeFromWatchList(String emailId,String dealId){
		List<String> dealList = INSTANCE.watchListMap.get(emailId);
		if(dealList == null){
			dealList = new ArrayList<String>();
			INSTANCE.watchListMap.put(emailId, dealList);
		}
		dealList.remove(emailId);
		return true;
	}
	
	public static List<Deal> getFavoriteDeals(String emailId){
		List<String> dealList = INSTANCE.watchListMap.get(emailId);

		if(dealList == null){
		  return Collections.EMPTY_LIST;
		}
		List<Deal> deals = new ArrayList<>();
		for (String dealId : dealList) {
			deals.add(DealMap.INSTANCE.getDeal(dealId));
		} 
		
		return deals;
	}

}
